package com.jari.lg.service.profile.device;

import com.jari.lg.domain.CrossBase;
import com.jari.lg.domain.DevBase;
import com.jari.lg.domain.DeverrIntervalHisEntity;
import com.jari.lg.mapper.DeverrIntervalHisEntityMapper;
import com.jari.lg.utils.BaseData;
import com.jari.lg.utils.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DeverrIntervalHisService {

    @Autowired
    private DeverrIntervalHisEntityMapper deverrIntervalHisEntityMapper;

    /*
    *  每天产生一定的数据
    * */
    public void makeInfo(){
        DeverrIntervalHisEntity entity;
        List<DevBase> devBases = BaseData.devBaseList;
        List<CrossBase> crossBases = BaseData.crossBaseList;
        for(int i = 0 ; i < 100; i ++){
            entity = generate(devBases.get(Utils.makeRandInt(devBases.size())), crossBases);
            deverrIntervalHisEntityMapper.insert(entity);
        }
    }


    private DeverrIntervalHisEntity generate(DevBase devBase, List<CrossBase> crossBases){
        DeverrIntervalHisEntity entity = new DeverrIntervalHisEntity();
        entity.setDevcode(devBase.getDevicecode());
        entity.setDevname(devBase.getDevicename());
        entity.setDevtype(devBase.getDevicetype());
        entity.setEnddatetime(Utils.makeAfterDate(Utils.makeRandInt(300)));
        entity.setStartdatetime(new Date());
        entity.setLat(crossBases.stream().filter(x -> x.getCrosscode().equals(devBase.getCrosscode())).findFirst().get().getCrosslat().doubleValue());
        entity.setLon(crossBases.stream().filter(x -> x.getCrosscode().equals(devBase.getCrosscode())).findFirst().get().getCrosslon().doubleValue());
        return entity;
    }

}
